home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Human Interface Toolbox / IconUtilCheck / IconUtilCheck.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  2.7 KB  |  93 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        IconUtilCheck.c
  3.  
  4.     Contains:    According to the Tech Note OV - 16, "Inside Macintosh: More Macintosh 
  5.                 Toolbox, page 5-7, specifies that the gestaltIconUtilitiesAttr - 'icon'
  6.                 gestalt selector can be used to determine whether the icon utilities
  7.                 are present under System 7.x.   Note that this selector is included in
  8.                 the GestaltEqu files.  It turns out that this selector is not
  9.                 implemented until System Software v7.1.2.  To check for the existence of
  10.                 these utilities, use the TrapAvailable code to check for the 
  11.                 _IconDispatch, (0xABC9) trap.  The TrapAvailable code is presented in
  12.                 Inside Macintosh VI 3-8, and as sample code in many of the snippets
  13.                 on the Developer CD."
  14.  
  15.                 This snippet shows how to determine whether the Icon Utilities
  16.                 are available.
  17.  
  18.     Written by: Virginia (Ginny) McCulloh    
  19.  
  20.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  21.  
  22.                 You may incorporate this Apple sample source code into your program(s) without
  23.                 restriction. This Apple sample source code has been provided "AS IS" and the
  24.                 responsibility for its operation is yours. You are not permitted to redistribute
  25.                 this Apple sample source code as "Apple sample source code" after having made
  26.                 changes. If you're going to re-distribute the source, we require that you make
  27.                 it clear in the source that the code was descended from Apple sample source
  28.                 code, but that you've made changes.
  29.  
  30.     Change History (most recent first):
  31.                 8/6/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  32.                 
  33.  
  34. */
  35.  
  36. #include <stdio.h>
  37. #include <Types.h>
  38. #include <OSUtils.h>
  39. #include <GestaltEqu.h>
  40.  
  41. #ifndef __TRAPS__
  42. #include <Traps.h>
  43. #endif
  44.  
  45. #define    TrapMask        0x0800
  46.  
  47.  
  48. Boolean TrapAvailable(short theTrap);
  49. short NumToolboxTraps(void);
  50. TrapType GetTrapType(short theTrap);
  51.     
  52. short NumToolboxTraps(void)
  53. {
  54.     if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E,ToolTrap))
  55.         return 0x0200;
  56.     else
  57.         return 0x0400;
  58. }
  59.  
  60. TrapType GetTrapType(short theTrap)
  61. {
  62.     if ((theTrap & TrapMask) > 0)
  63.         return ToolTrap;
  64.     else
  65.         return OSTrap;
  66. }
  67.  
  68. Boolean TrapAvailable(short theTrap)
  69. {
  70.     TrapType tType;
  71.     Boolean isAvail;
  72.     
  73.     tType = GetTrapType(theTrap);
  74.     if (tType == ToolTrap)
  75.         {
  76.             theTrap &= 0x07FF;
  77.             if (theTrap >= NumToolboxTraps())
  78.                 theTrap = _Unimplemented;
  79.         }
  80.     
  81.     isAvail = NGetTrapAddress(theTrap, tType) != NGetTrapAddress(_Unimplemented, ToolTrap);
  82.     return isAvail;
  83. }
  84.  
  85. void main(void)
  86. {
  87.     printf("Testing for presence of Icon Utilities\n");
  88.     if (TrapAvailable(_IconDispatch))
  89.         printf("Icon Utilities are available\n");
  90.     else
  91.         printf("Icon Utilities are not available\n");
  92. }
  93.